<!doctype html>
<html lang="en" class="fixed">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>编辑用户资料</title>
    <link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
    <link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/animate.css/animate.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/font-awesome/css/font-awesome.css')) ?>">
    <link rel="stylesheet"
          href="<?php xcho(loadSource('/assets/plugins/data-table/media/css/dataTables.bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/style.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/layui/css/layui.css')) ?>" media="all">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/app.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/css/new_main.css')) ?>">
    
    <style>
        .pagination {
            margin: 0;
        }
    </style>
</head>

<body><?php include_once TPL_PATH . 'public/nav.phtml'; ?>

<div class="wrap">
    <div class="page-body " style="padding: 0">
        <div class="content" style="margin: 0;background: #ececec">
            <div class="row">
                <div class="col-sm-12">
                    <div class="panel">
                        <div class="panel-content layui-form">
                            <div class="row">
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">姓名:</label>
                                    <div class="col-sm-8">
                                        <input class="form-control" name="full_name" type="text" value="<?php xcho($list['full_name']) ?>" placeholder="姓名">
                                    </div>
                                </div>
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">
                                        <span class="required" aria-required="true">*</span>用户名:
                                    </label>
                                    <div class="col-sm-8">
                                        <input required="" name="user_name" aria-required="true" class="form-control"
                                               type="text"  value="<?php xcho($list['user_name']) ?>" placeholder="用户名">
                                    </div>
                                </div>


                            </div>
                            <div class="row">
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">邮箱:</label>
                                    <div class="col-sm-8">
                                        <input class="form-control email" name="email" type="text" value="<?php xcho($list['email']) ?>" placeholder="邮箱">
                                    </div>
                                </div>
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">手机号:</label>
                                    <div class="col-sm-8">
                                        <input class="form-control mobile" name="cellphone" type="text" value="<?php xcho($list['cellphone']) ?>" placeholder="手机号">
                                    </div>
                                </div>
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">分机号:</label>
                                    <div class="col-sm-8">
                                        <input class="form-control" name="ext" type="text" value="<?php xcho($list['ext']) ?>" placeholder="分机号">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">IP
                                        登录:</label>
                                    <div class="col-sm-8">
                                        <input class="form-control" name="ip" type="text" value="<?php xcho($list['ip']) ?>" placeholder="IP 登录">
                                    </div>
                                </div>
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">状态:</label>
                                    <div class="col-sm-8">
                                        <div class="layui-form-item">
                                            <select lay-filter="status" name="status_value" id="">
                                                <?php if($list['status_value']=='active') {  ?>
                                                    <option value="active" selected>激活</option>
                                                    <option value="disable">禁用</option>
                                                <?php } ?>

                                                <?php if($list['status_value']=='disable') {  ?>
                                                    <option value="active" >激活</option>
                                                    <option value="disable" selected>禁用</option>
                                                <?php }else{ ?>
                                                    <option value="" >请选择</option>
                                                    <option value="active" >激活</option>
                                                    <option value="disable" selected>禁用</option>
                                                <?php } ?>

                                            </select>
                                        </div>

                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">角色:</label>
                                    <div class="col-sm-8">
                                        <input class="form-control" name="role_id" id="role-picker" type="text" data-tid="<?php  xcho($list['role_id']) ?>" value="<?php  xcho($list['role_name']) ?>"  placeholder="角色">
                                    </div>
                                </div>
                                <div class="col-xs-4">
                                    <label class="col-sm-4 control-label" style="line-height: 34px;text-align: right">分组:</label>
                                    <div class="col-sm-8">
                                        <input class="form-control" name="group_id" id="group-picker" type="text" data-tid="<?php  xcho($list['group_id']) ?>" value="<?php  xcho($list['group_name']) ?>"  placeholder="分组">
                                    </div>
                                </div>
                            </div>

                        </div>
                        <div class="panel-footer">
                            <div class="top_pages bottom_pages" style="float: right">
                                <button class="layui-btn layui-btn-normal layui-btn-small" id="save">保存</button>
                                <button style="margin-left: 24px" class="layui-btn layui-btn-primary layui-btn-small"
                                        id="return">取消
                                </button>
                            </div>
                            <div style="clear: both"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="scroll-to-top"><i class="fa fa-angle-double-up"></i></a>
    </div>
</div>
<div class="modal fade" id="info-modal-group" tabindex="-1" role="dialog" aria-labelledby="modal-info-label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header state modal-info">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="modal-info-label"><i class="fa fa-info"></i></h4>
            </div>
            <div class="modal-body" style="min-height: 150px;">
                <ul class="ztree" id="group"></ul>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="sureGroup" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" id="returnGroup" data-dismiss="modal">返回</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="info-modal-role" tabindex="-1" role="dialog" aria-labelledby="modal-info-label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header state modal-info">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="modal-info-label"><i class="fa fa-info"></i></h4>
            </div>
            <div class="modal-body" style="min-height: 150px;">
                <ul class="ztree" id="role"></ul>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="sureRole" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" id="returnRole" data-dismiss="modal">返回</button>
            </div>
        </div>
    </div>
</div>

<input type="hidden" name="save_user" value="<?php xcho($save_user) ?>"/>
<input type="hidden" name="group_list" value="<?php xcho($groupList) ?>"/>
<input type="hidden" name="role_list" value="<?php xcho($roleList) ?>"/>
<script src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/jquery.dataTables.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/dataTables.bootstrap.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/dataTables.responsive.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>

<script src="<?php xcho(loadSource('/assets/plugins/layui/layui.all.js')) ?>" charset="utf-8"></script>
<script src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.core.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.excheck.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.exedit.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets/js/validate.js')) ?>"></script>
<script>
    $(function () {


        "use strict";
        layui.use('table', function(){
            var table = layui.table;
            var $ = layui.jquery,
                form = layui.form;
            var status = "active";
            form.on('select(status)',function (data){
                status = data.value;
            });
            var settingGroup = {
                view: {
                    selectedMulti: false
                },
                edit: {
                    enable: false
                },
                data: {
                    keep: {
                        parent:true,
                        leaf:true
                    },
                    simpleData: {
                        enable: true
                    }
                }
            };
            var zNodes = getListData();
            $.each(zNodes,function(i,item){
                item.isParent = true;
            })
            $.fn.zTree.init($("#group"), settingGroup, zNodes);
            var settingRole = {
                view: {
                    selectedMulti: false
                },
                edit: {
                    enable: false
                },
                data: {
                    keep: {
                        parent:true,
                        leaf:true
                    },
                    simpleData: {
                        enable: true
                    }
                }
            };
            var zNodesRole = getRoleListData();
            $.each(zNodesRole,function(i,item){
                item.isParent = true;
            })
            $.fn.zTree.init($("#role"), settingRole, zNodesRole);
            $("#save").on("click", function () {
                var isContine = validateF();
                if(!isContine) return false;
                $.ajax({
                    url: $("input[name='save_user']").val(),
                    type: 'post',
                    data: {
                        user_id:getUrlParam("user_id"),
                        full_name: $("input[name='full_name']").val(),
                        user_name: $("input[name='user_name']").val(),
//                        password: $("input[name='password']").val(),
                        email: $("input[name='email']").val(),
                        cellphone: $("input[name='cellphone']").val(),
                        ext: $("input[name='ext']").val(),
                        role_id: $("input[name='role_id']").attr("data-tid"),
                        ip: $("input[name='ip']").val(),
                        group_id:$("input[name='group_id']").attr("data-tid"),
                        status_value: status
                    },
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if (data.success == 1) {
                            location.href = "/user/user/index"
                        } else {

                        }
                    },
                    complete: function () {

                    },
                    error: function () {

                    }
                });
            });
            $("#return").on("click", function () {
                location.href = "/user/user/index"
            })
            function getRoleListData() {
                var data_list ;
                $.ajax({
                    url: $("input[name='role_list']").val(),
                    type: 'post',
                    async:false,
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if(data.success == 1){
                            data_list = data.data;
                        }else{
                        }
                    },
                    complete:function(){
                    },
                    error: function () {

                    }
                });
                return data_list;
            }
            function getListData(){
                var data_list ;
                $.ajax({
                    url: $("input[name='group_list']").val(),
                    type: 'post',
                    async:false,
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if(data.success == 1){
                            data_list = data.data_list;
                        }else{
                        }
                    },
                    complete:function(){
                    },
                    error: function () {

                    }
                });
                return data_list;
            }
            console.log($("input[name='group_list']").val())
            $("#group-picker").focus(function(){
                $('#info-modal-group').modal({
                    keyboard: false,
                    backdrop:false
                });
            });
            $("#role-picker").focus(function(){
                $('#info-modal-role').modal({
                    keyboard: false,
                    backdrop:false
                });
            });
            $("#sureGroup").on("click",function(){
                var zTree = $.fn.zTree.getZTreeObj("group"),
                    nodes = zTree.getSelectedNodes(),
                    treeNode = nodes[0];
                console.log(treeNode);
                if (nodes.length == 0) {
                    alert("请先选择一个节点");
                    return;
                }
                $("#group-picker").val(treeNode.name).attr("data-tid",treeNode.id);
            })
            $("#sureRole").on("click",function(){
                var zTree = $.fn.zTree.getZTreeObj("role"),
                    nodes = zTree.getSelectedNodes(),
                    treeNode = nodes[0];
                console.log(treeNode);
                if (nodes.length == 0) {
                    alert("请先选择一个节点");
                    return;
                }
                $("#role-picker").val(treeNode.name).attr("data-tid",treeNode.id);
            })
        })
        //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }

    });
</script>
    <?php include_once TPL_PATH . 'public/foot_script.phtml'; ?>

<button id="top" style="height: 50px;width: 50px;"></button></body>

</html>
